/*
 * Copyright © 2024-2025 Wenze Wei
 *
 * This file is part of StadionOS.
 *
 * This Source Code Form is subject to the terms of the GNU General Public License, v. 2.0.
 * You can obtain a copy of the GPL at
 * https://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
 * the specific language governing rights and limitations under the License.
 */

#include "../include/malloc.h"

/**
 * @brief Allocates memory for an array of objects.
 *
 * This function allocates memory for an array of 'count' objects, each 'size' bytes in size.
 * The allocated memory is initialized to zero.
 *
 * @param count The number of objects in the array.
 * @param size The size of each object.
 * @return void* A pointer to the allocated memory, or NULL on error.
 */
void *Scalloc(size_t count, size_t size) {
    size_t total_size = count * size;
    void *ptr = Smalloc(total_size);

    if (ptr)
       Smemset(ptr, 0, total_size);

    return ptr;
}

/**
 * @brief Aligns a size to the alignment boundary.
 *
 * This function aligns 'size' to the alignment boundary defined by ALIGNMENT.
 *
 * @param size The size to align.
 * @return size_t The aligned size.
 */
size_t ALIGN(size_t size) {
    return (size + (ALIGNMENT - 1)) & ~(ALIGNMENT - 1);
}
